package sedh.project

import grails.test.*


class ServicoTests extends GrailsUnitTestCase {
	
	def serv
    protected void setUp() {
        super.setUp()
		
		mockForConstraintsTests(Servico)
		serv = new Servico(nome: "Servico1", descricao: "Descricao1")
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testUnique() {
		def mesmo = new Servico(nome: "Servico1", descricao : "Descricao1")
		mockForConstraintsTests(Servico, [mesmo])
		
		assertFalse serv.validate()
		
		serv = new Servico(nome: "OutroServico", descricao : "Descricao1")
		assertTrue serv.validate()
		
    }

	void testBlank() {
        serv = new Servico(name: '', descricao: '')
        assertFalse serv.validate()
        

        serv = new Servico(nome: "Servico1", descricao: "Descricao1")
        assertTrue serv.validate()
    }
	
	void testNullable() {
		serv = new Servico()
		assertFalse serv.validate()
		assertEquals 'Nome eh null.', 'nullable', serv.errors['nome']
		assertEquals 'Descricao eh null', 'nullable', serv.errors['descricao']
		
	}
	
	void testMaxSize() {
		serv.nome = 'This name is just way longer than the maxSize argument defines.This name is just way longer than the maxSize argument defines.'
		serv.descricao = 'The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.'
		assertFalse serv.validate()
		assertEquals 'Nome muito grande.', 'size', serv.errors['nome']
		assertEquals 'Descricao muito grade.', 'maxSize', serv.errors['descricao']

		serv.nome = 'Servico2'
		serv.descricao = 'Um texto razoavelmente bom para uma pequena descricao'
		assertTrue serv.validate()
	}
	
	void testMinSize() {
		serv.nome = "s"
		assertFalse serv.validate()
		assertEquals 'Nome muito pequeno.', 'size', serv.errors['nome']
		
		serv.nome = "NM"
		assertTrue serv.validate()
		
	}
}
